import java.util.Stack;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 07 - 08
 * Time: 20:38
 */
class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}
class Solution3 {
    public int[] reversePrint(ListNode head) {
        ListNode cur = head;
        Stack<ListNode> stack = new Stack<ListNode>();
        while(cur != null) {
            stack.push(cur);
            cur = cur.next;
        }
        int size = stack.size();
        int[] arr = new int[size];
        for(int i = 0; i < size; i++) {
            arr[i] = stack.pop().val;
        }
        return arr;
    }
}
